/**
 * Copyright 2006 Brad Reynolds
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.leeloo.databinding.ui.event;

import org.leeloo.databinding.internal.ui.LabeledTreeNode;
import org.leeloo.databinding.internal.ui.LabeledTreeNodeBuilder;
import org.leeloo.databinding.ui.descriptor.DiffDescriptor;
import org.leeloo.databinding.ui.descriptor.ObservableDescriptor;

/**
 * Value change event.
 * 
 * @author Brad Reynolds
 */
public class ValueChangeEvent extends AbstractEvent {
    private ObservableDescriptor observableDescriptor;
    private DiffDescriptor diffDescriptor;
    
    public ValueChangeEvent() {   
    }

    public String getTypeDisplay() {
        return Messages.getString("ValueChangeEvent.value_change_event"); //$NON-NLS-1$
    }
    
    public String getDisplay() {
        String result = null;
        if (diffDescriptor != null) {
            result = diffDescriptor.getCleanToString();
        } else {
            result = "diff == null"; //$NON-NLS-1$
        }
        
        return result;
    }
    
    /**
     * @return the diffDescriptor
     */
    public DiffDescriptor getDiffDescriptor() {
        return diffDescriptor;
    }

    /**
     * @param diffDescriptor the diffDescriptor to set
     */
    public void setDiffDescriptor(DiffDescriptor diffDescriptor) {
        this.diffDescriptor = diffDescriptor;
    }

    /**
     * @return the observableDescriptor
     */
    public ObservableDescriptor getObservableDescriptor() {
        return observableDescriptor;
    }

    /**
     * @param observableDescriptor the observableDescriptor to set
     */
    public void setObservableDescriptor(ObservableDescriptor observableDescriptor) {
        this.observableDescriptor = observableDescriptor;
    }

    public Object getAdapter(Class adapter) {
        Object result = null;
        if (LabeledTreeNode.class.equals(adapter)) {
            LabeledTreeNode thisNode = new LabeledTreeNode(this);
            thisNode.setLabel(Messages.getString("ValueChangeEvent.event_name")); //$NON-NLS-1$

            LabeledTreeNodeBuilder builder = LabeledTreeNodeBuilder.forNode(thisNode);
            builder.addChild(observableDescriptor, Messages.getString("ValueChangeEvent.observable")); //$NON-NLS-1$
            builder.addChild(diffDescriptor, Messages.getString("ValueChangeEvent.diff")); //$NON-NLS-1$
            result = builder.build();
        }

        return result;
    }
}